home *** CD-ROM | disk | FTP | other *** search
- // PXEWIN - (C) Copyright 1992 by Beam Engineering, INC.
-
- // BROWSEFM.CPP //
-
- // Contents ----------------------------------------------------------------
- //
- // This module contains the members for the class BrowserFrame.
- //
- // End ---------------------------------------------------------------------
-
- // External Reference Name for this Header ---------------------------------
-
- #ifndef BROWSEFM_CPP
- #define BROWSEFM_CPP
-
- // End ---------------------------------------------------------------------
-
- // Interface Dependencies --------------------------------------------------
-
- #ifndef BROWSEFM_HPP
- #include "browsefm.hpp"
- #endif // BROWSEFM_HPP //
-
- #ifndef PXI_CPP
- #include "pxi.cpp"
- #endif // PXI_CPP //
-
- // End ---------------------------------------------------------------------
-
- // member CursorWait of BrowserFrame //
-
- inline void BrowserFrame::CursorWait(RTMessage)
- {
- MyClass->hCursor = LoadCursor(NULL,IDC_WAIT);
- SetCursor(MyClass->hCursor);
- }
-
- // Description -------------------------------------------------------------
- //
- // Sets cursor to wait type cursor.
- //
- // End ---------------------------------------------------------------------
-
- // member CursorNormal of BrowserFrame //
-
- inline void BrowserFrame::CursorNormal(RTMessage)
- {
- MyClass->hCursor = LoadCursor(NULL,IDC_ARROW);
- SetCursor(MyClass->hCursor);
- }
-
- // member MenuItemDisable of BrowserFrame //
-
- inline void BrowserFrame::MenuItemDisable(int item)
- {
- HMENU hMenu; /* Menu handle */
-
- // Get the menu handle
-
- hMenu = GetMenu(HWindow);
-
- // Disable menu item.
-
- EnableMenuItem(hMenu,item,MF_GRAYED);
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Disables selected menu item.
- //
- // Parameter
- //
- // item. Is the menu item number to disable.
- //
- // End ---------------------------------------------------------------------
-
- // member MenuItemEnable of BrowserFrame //
-
- inline void BrowserFrame::MenuItemEnable(int item)
- {
- HMENU hMenu; /* Menu handle */
-
- // Get the menu handle
-
- hMenu = GetMenu(HWindow);
-
- // Enable menu item.
-
- EnableMenuItem(hMenu,item,MF_ENABLED);
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Disables selected menu item.
- //
- // Parameter
- //
- // item. Is the menu item number to disable.
- //
- // End ---------------------------------------------------------------------
-
- // member GetWindowClass of BrowserFrame //
-
- inline void BrowserFrame::GetWindowClass(WNDCLASS& AWndClass)
- {
- TWindow::GetWindowClass(AWndClass);
- MyClass = &AWndClass;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Set up windows class object.
- //
- // End ---------------------------------------------------------------------
-
- // constructor BrowserFrame //
-
- inline BrowserFrame::BrowserFrame(LPSTR ATitle):
- TMDIFrame(ATitle,"COMMANDS")
- {
- // Create a windows class buffer
-
- MyClass = new WNDCLASS;
-
- // Open the PXEngine for windows in single client mode
-
- engine = new PXI("me",PXSINGLECLIENT);
- if((error = engine->RetPXError()) != PXSUCCESS)
- {
-
- MessageBox(HWindow,engine->RetPXErrorMsg(),
- "Database Error",MB_OK);
- CloseWindow();
- }
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Create a MDI Browser frame.
- //
- // Parameters
- //
- // Pass of the frame title and commands menu to the MDI window.
- //
- // Description
- //
- // Initialize engine in single client mode. If you get an error, let
- // the message box say what it is and close the window.
- //
- // End ---------------------------------------------------------------------
-
- // member CreateChild of BrowserFrame //
-
- inline PTWindowsObject BrowserFrame::CreateChild()
- {
- NewChild = new Browser(this,GetChildCount()+1);
-
- // If the database exists, show it
-
- if(NewChild->GetDB() == EXISTS){
-
- // Enable save menus
-
- MenuItemEnable(CM_FILESAVE);
- MenuItemEnable(CM_FILESAVEAS);
- return GetApplication()->MakeWindow(NewChild);
- }
- // else kill the window and return NULL
-
- delete NewChild;
- return NULL;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Creates a new Browser window.
- //
- // Return Value
- //
- // Returns pointer to Browser window NewChild
- //
- // Functional Description
- //
- // 1. Initialize a new child window Browser.
- //
- // 2. If the new child exists, make the new window.
- //
- // 3. Else kill the child and return NULL.
- //
- // End ---------------------------------------------------------------------
-
- // destructor BrowserFrame //
-
- inline BrowserFrame::~BrowserFrame()
- {
- CloseChildren();
- delete engine;
- delete MyClass;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Call CloseChildren to close any open children. Delete the engine
- // and windows class objects.
- //
- // End ---------------------------------------------------------------------
-
- // function CountChild //
-
- void CountChild(Pvoid,Pvoid CountPtr)
- {
- ++*(Pint)CountPtr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // This function keeps track of the number of child windows you have
- // opened.
- //
- // Parameters
- //
- // 1. First parameter is a pointer for the child. It's not used.
- //
- // 2. Second parameter is the counter.
- //
- // Return Value
- //
- // None.
- //
- // Functional Description
- //
- // For each window increment the counter.
- //
- // End ---------------------------------------------------------------------
-
- // member build of BrowserFrame //
-
- PTStreamable BrowserFrame::build()
- {
- return new BrowserFrame(streamableInit);
- }
-
- TStreamableClass RegBrowserFrame("BrowserFrame",BrowserFrame::build,
- __DELTA(BrowserFrame));
-
- // Description -------------------------------------------------------------
- //
- // When the streamable constructor is called, TStreamable dispatches
- // the build member to construct the object. To do this, it must
- // know where to find this member functions for the specific class.
- // This is the reason for the stream registration.
- //
- // End ---------------------------------------------------------------------
-
- // member read of BrowserFrame //
-
- inline Pvoid BrowserFrame::read(Ripstream)
- {
- return this;
- }
-
- // member write of BrowserFrame //
-
- inline void BrowserFrame::write(Ropstream)
- {
-
- }
-
- // member SetupWindow of BrowserFrame //
-
- inline void BrowserFrame::SetupWindow()
- {
- TMDIFrame::SetupWindow();
- Show(SW_SHOWMAXIMIZED);
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Call the MDI frame setup and set maximized show.
- //
- // End ---------------------------------------------------------------------
-
- // member GetChildCount of BrowserFrame //
-
- inline int BrowserFrame::GetChildCount()
- {
- int Count = 0;
- ForEach(CountChild,&Count);
- return Count;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Lets the Frame window count the children.
- //
- // End ---------------------------------------------------------------------
-
- // function SaveChildren //
-
- void SaveChildren(Pvoid P,Pvoid os)
- {
- PBrowser ptr;
-
- ptr = (PBrowser)P;
- ptr->WriteChildren(*(opstream *)os);
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Writes Child to the stream.
- //
- // Parameters
- //
- // P. Is the Child Object pointer.
- //
- // os. Is the Stream pointer.
- //
- // End ---------------------------------------------------------------------
-
- // member WriteChildren of BrowserFrame //
-
- void BrowserFrame::WriteChildren(Ropstream os)
- {
- int num_children; /* number of child windows */
-
- num_children = GetChildCount();
-
- os << num_children;
- ForEach(SaveChildren,&os);
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Get the child count and put it on the stream so the desktop reader
- // will know how many children to take off the stream.
- //
- // For each child, save it to the stream.
- //
- // Parameter
- //
- // os. Is the output stream.
-
- // End ---------------------------------------------------------------------
-
- // member ReadChildren of BrowserFrame //
-
- void BrowserFrame::ReadChildren(Ripstream is)
- {
- int num_children; /* number of child windows */
- int i; /* Child index */
-
- is >> num_children;
-
- // Create your children.
-
- for(i = 0;i < num_children;i++)
- {
- NewChild = new Browser(this,GetChildCount()+1);
-
- // If there are no errors in reading the child, make the
- // window.
-
- if(!NewChild->ReadChildren(is))
- GetApplication()->MakeWindow(NewChild);
- else{
- delete NewChild;
- NewChild = NULL;
- }
- }
-
- // If you got children off the stream, enable the save menus.
-
- if(num_children > 0)
- {
- MenuItemEnable(CM_FILESAVE);
- MenuItemEnable(CM_FILESAVEAS);
- }
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Read children off the stream.
- //
- //
- // Parameters
- //
- // is. Is the input stream.
- //
- // Functional Description
- //
- // Get the number of children off the stream.
- //
- // For each child, construct the child, call it's reader and make the
- // window.
- //
- // End ---------------------------------------------------------------------
-
- // member CreateBrowser of BrowserFrame //
-
- inline void BrowserFrame::CreateBrowser(RTMessage)
- {
- CreateChild();
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Creates child window when command is dispatched.
- //
- // End ---------------------------------------------------------------------
-
- // member CheckChildren of BrowserFrame //
-
- inline void BrowserFrame::CheckChildren(RTMessage)
- {
- int count; /* Number of children */
-
- count = GetChildCount();
- if(count == 1)
- {
- MenuItemDisable(CM_FILESAVE);
- MenuItemDisable(CM_FILESAVEAS);
- }
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Responds to a message sent by a Browser to check your children
- //
- // Parameters
- //
- // RTMessage. This is the message sent.
- //
- // Functional Description --------------------------------------------------
- //
- // Get the child count. If there are no children then disable the save
- // menus.
- //
- // End ---------------------------------------------------------------------
-
- // member PXError of BrowserFrame //
-
- inline void BrowserFrame::PXError(RTMessage)
- {
- // If the new child still exists, get the engine error string
- // and display it in the message box.
-
- if(NewChild)
- MessageBox(HWindow,NewChild->my_display->RetPXErrorMsg(),
- "DataBase Warning",MB_OK);
- }
-
- // Summary -----------------------------------------------------------------
- //
- // This will display Engine error messages in the MDI frame window.
- //
- // End ---------------------------------------------------------------------
-
- // member OpenDeskTop of BrowserFrame //
-
- inline void BrowserFrame::OpenDeskTop(RTMessage)
- {
- char sname[MAXPATH]; /* Desktop name */
-
- strcpy(sname,"*.dtf");
- if(GetApplication()->ExecDialog(
- new TFileDialog(this,SD_FILEOPEN,
- sname)) == IDOK)
- {
- // Open the file for reading:
-
- ifpstream is(sname);
-
-
- if(is.bad())
- MessageBox(HWindow,"Unable to open file","File Error",
- MB_OK | MB_ICONEXCLAMATION);
-
- else
- ReadChildren(is);
- is.close();
- }
- }
-
- // Description -------------------------------------------------------------
- //
- // Opens the desktop as it was last saved to the stream. Create a file
- // name mask and call the file dialog. If file is found, create an
- // input stream, check to see if it's OK and read the children off the
- // stream.
- //
- // End ---------------------------------------------------------------------
-
- // member SaveDeskTop of BrowserFrame //
-
- inline void BrowserFrame::SaveDeskTop(RTMessage)
- {
- char sname[MAXPATH]; /* Desktop name */
-
- strcpy(sname,"pxdesk.dtf");
- if(GetApplication()->ExecDialog(
- new TFileDialog(this,SD_FILESAVE,
- sname)) == IDOK)
- {
- // Open the file:
-
- ofpstream os(sname);
-
- // Write the to the stream
-
- WriteChildren(os);
-
- // Close the stream:
-
- os.close();
- }
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Save the desktop to a file. Construct a file mask. Call the file
- // dialog. If the file is found, open the stream for output, write the
- // children, and close the stream.
- //
- // End ---------------------------------------------------------------------
-
- #endif // BROWSEFM_CPP //